// ************************************************************************
// Repositories classes for ADO.NET Extension...
// ************************************************************************
namespace DAL.BetpointAdvanced.BNL.ADO.Repositories
{
    using System;
    using System.Data;
    using GrayParrot.Core.Data;
    using GrayParrot.Data.ADONET;
    using System.Collections.Generic;
	using DAL.BetpointAdvanced.BNL.ADO.Utilities;
    public class BNL_ElencoCodici3DSecureRepository : Repository<BNL_ElencoCodici3DSecure, BNL_ElencoCodici3DSecureAggregateRoot>
    {
	    private DbContext m_context = null;

		public BNL_ElencoCodici3DSecureRepository(DbContext context) : base(context)
        {
		    m_context = context;
        }

        public override void Add(BNL_ElencoCodici3DSecure item)
        {
		    if(!this.Context.HasValidConnection) return;

		    try
			{
				using (var command = this.Context.CreateCommand())
				{
					command.Add(item);
					command.ExecuteNonQuery();
				}
			}
			catch(Exception ex)
			{
			    ex.Data["MName"] = "BNL_ElencoCodici3DSecureRepository.Add";
			    m_context.ErrorHandler(ex);
			    //throw new Exception(ex0.Message, ex0);
			}
            //todo: Get identity. Depends on the db engine.
        }

        public override void Update(BNL_ElencoCodici3DSecure item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Update(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_ElencoCodici3DSecure item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Remove(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_ElencoCodici3DSecureAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.RemoveByKey_BNL_ElencoCodici3DSecure(key);
                command.ExecuteNonQuery();
            }
        }

        public override IEnumerable<BNL_ElencoCodici3DSecure> FindAll()
        {   
            if(!this.Context.HasValidConnection) return null;        
			using (var command = this.Context.CreateCommand())
            {
                command.CommandText = BNL_ElencoCodici3DSecure_Util.FindAllCmd;
                return ToList(command);
            }
        }

        public override BNL_ElencoCodici3DSecure Find(BNL_ElencoCodici3DSecureAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return null;
            using (var command = this.Context.CreateCommand())
            {
                command.Find_BNL_ElencoCodici3DSecure(key);
                return ToEntity(command);
            }
        }

        public override IEnumerable<BNL_ElencoCodici3DSecure> Find(System.Linq.Expressions.Expression<Func<BNL_ElencoCodici3DSecure, bool>> predicate)
        {
		    if(!this.Context.HasValidConnection) return null;
            
			var translator = new QueryTranslator();
            string whereClause = translator.Translate(predicate);

            using (var command = this.Context.CreateCommand())
            {
                command.CommandText = "SELECT * FROM BNL.Customers WHERE " + whereClause;
                return ToList(command);
            }
        }

        protected override void Map(IDataRecord record, BNL_ElencoCodici3DSecure entity)
        {
            record.Map_BNL_ElencoCodici3DSecure(entity);
        }
	}

    public class BNL_ReportTransazioniRepository : Repository<BNL_ReportTransazioni, BNL_ReportTransazioniAggregateRoot>
    {
	    private DbContext m_context = null;

		public BNL_ReportTransazioniRepository(DbContext context) : base(context)
        {
		    m_context = context;
        }

        public override void Add(BNL_ReportTransazioni item)
        {
		    if(!this.Context.HasValidConnection) return;

		    try
			{
				using (var command = this.Context.CreateCommand())
				{
					command.Add(item);
					command.ExecuteNonQuery();
				}
			}
			catch(Exception ex)
			{
			    ex.Data["MName"] = "BNL_ReportTransazioniRepository.Add";
			    m_context.ErrorHandler(ex);
			    //throw new Exception(ex0.Message, ex0);
			}
            //todo: Get identity. Depends on the db engine.
        }

        public override void Update(BNL_ReportTransazioni item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Update(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_ReportTransazioni item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Remove(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_ReportTransazioniAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.RemoveByKey_BNL_ReportTransazioni(key);
                command.ExecuteNonQuery();
            }
        }

        public override IEnumerable<BNL_ReportTransazioni> FindAll()
        {   
            if(!this.Context.HasValidConnection) return null;        
			using (var command = this.Context.CreateCommand())
            {
                command.CommandText = BNL_ReportTransazioni_Util.FindAllCmd;
                return ToList(command);
            }
        }

        public override BNL_ReportTransazioni Find(BNL_ReportTransazioniAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return null;
            using (var command = this.Context.CreateCommand())
            {
                command.Find_BNL_ReportTransazioni(key);
                return ToEntity(command);
            }
        }

        public override IEnumerable<BNL_ReportTransazioni> Find(System.Linq.Expressions.Expression<Func<BNL_ReportTransazioni, bool>> predicate)
        {
		    if(!this.Context.HasValidConnection) return null;
            
			var translator = new QueryTranslator();
            string whereClause = translator.Translate(predicate);

            using (var command = this.Context.CreateCommand())
            {
                command.CommandText = "SELECT * FROM BNL.Customers WHERE " + whereClause;
                return ToList(command);
            }
        }

        protected override void Map(IDataRecord record, BNL_ReportTransazioni entity)
        {
            record.Map_BNL_ReportTransazioni(entity);
        }
	}

    public class BNL_TransazioniRepository : Repository<BNL_Transazioni, BNL_TransazioniAggregateRoot>
    {
	    private DbContext m_context = null;

		public BNL_TransazioniRepository(DbContext context) : base(context)
        {
		    m_context = context;
        }

        public override void Add(BNL_Transazioni item)
        {
		    if(!this.Context.HasValidConnection) return;

		    try
			{
				using (var command = this.Context.CreateCommand())
				{
					command.Add(item);
					command.ExecuteNonQuery();
				}
			}
			catch(Exception ex)
			{
			    ex.Data["MName"] = "BNL_TransazioniRepository.Add";
			    m_context.ErrorHandler(ex);
			    //throw new Exception(ex0.Message, ex0);
			}
            //todo: Get identity. Depends on the db engine.
        }

        public override void Update(BNL_Transazioni item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Update(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_Transazioni item)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.Remove(item);
                command.ExecuteNonQuery();
            }
        }

        public override void Remove(BNL_TransazioniAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return;
            using (var command = this.Context.CreateCommand())
            {
                command.RemoveByKey_BNL_Transazioni(key);
                command.ExecuteNonQuery();
            }
        }

        public override IEnumerable<BNL_Transazioni> FindAll()
        {   
            if(!this.Context.HasValidConnection) return null;        
			using (var command = this.Context.CreateCommand())
            {
                command.CommandText = BNL_Transazioni_Util.FindAllCmd;
                return ToList(command);
            }
        }

        public override BNL_Transazioni Find(BNL_TransazioniAggregateRoot key)
        {
		    if(!this.Context.HasValidConnection) return null;
            using (var command = this.Context.CreateCommand())
            {
                command.Find_BNL_Transazioni(key);
                return ToEntity(command);
            }
        }

        public override IEnumerable<BNL_Transazioni> Find(System.Linq.Expressions.Expression<Func<BNL_Transazioni, bool>> predicate)
        {
		    if(!this.Context.HasValidConnection) return null;
            
			var translator = new QueryTranslator();
            string whereClause = translator.Translate(predicate);

            using (var command = this.Context.CreateCommand())
            {
                command.CommandText = "SELECT * FROM BNL.Customers WHERE " + whereClause;
                return ToList(command);
            }
        }

        protected override void Map(IDataRecord record, BNL_Transazioni entity)
        {
            record.Map_BNL_Transazioni(entity);
        }
	}

}

